home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / System / Extension / CountPatches / NumToPStr.c < prev    next >
Text File  |  1993-06-17  |  1KB  |  57 lines

  1. #define    convLength    5
  2.  
  3. StringPtr NumToPStr(short n);
  4. StringPtr    StrPCat(StringPtr a, StringPtr b);
  5.  
  6. /*
  7.  * don't reference globals in any of these routines.  Globals in an INIT depend
  8.  * upon the SetUpA4()/RememberA4() conventions.  See Think C's manual for more
  9.  * details.
  10.  */
  11.  
  12. /*******************************************************************************
  13.  
  14.     NumToPStr
  15.     
  16.     Convert a short into a decimal string, preceded by blanks.  If you want
  17.     the number preceeded by zeros, eliminate the line
  18.         if (n == 0) conv[0] = ' ';
  19.     from the for loop.
  20.  
  21. *******************************************************************************/
  22. StringPtr NumToPStr(short n)
  23. {
  24.     static unsigned char result[] = "$$$$$";
  25.     char        conv[]   = "0123456789";
  26.     short        i;
  27.     
  28.     for (i = 0; i < convLength; ++i) {
  29.         result[(convLength-1)-i] = conv[(n % 10)];
  30.         n /= 10;
  31.         if (n == 0) conv[0] = ' ';
  32.     }
  33.     result[0] = convLength-1;
  34.     return result;
  35. }
  36.  
  37.  
  38. /*******************************************************************************
  39.  
  40.     StrPCat
  41.     
  42.     Concatenate two pascal strings, returning a Pascal string.
  43.  
  44. *******************************************************************************/
  45. StringPtr    StrPCat(StringPtr a, StringPtr b)
  46. {
  47.     static Str255    result;
  48.     short        strSize;
  49.     
  50.     strSize = *a+*b+1;
  51.     
  52.     BlockMove(a, result, *a+1);
  53.     BlockMove(b+1, result+*a+1, *b);
  54.     *result = strSize-1;
  55.     return result;
  56. }
  57.